package vn.bk.hotel.map;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {
    }

    public String getJSONFromUrl(String url) {

	// Making HTTP request
	try {
	    // defaultHttpClient
	    DefaultHttpClient httpClient = new DefaultHttpClient();
	    HttpPost httpPost = new HttpPost(url);

	    HttpResponse httpResponse = httpClient.execute(httpPost);
	    HttpEntity httpEntity = httpResponse.getEntity();
	    is = httpEntity.getContent();

	} catch (Exception e) {
	    e.printStackTrace();
	}
	try {
	    BufferedReader reader = new BufferedReader(new InputStreamReader(
		    is, "iso-8859-1"), 8);
	    StringBuilder sb = new StringBuilder();
	    String line = null;
	    while ((line = reader.readLine()) != null) {
		sb.append(line + "\n");
	    }

	    json = sb.toString();
	    is.close();
	} catch (Exception e) {
	    Log.e("Buffer Error", "Error converting result " + e.toString());
	}
	return json;

    }
}